<?php
require_once("User_type.class.php");

class Session
{
  private $logged_in;
  private $user_ID;
  private $user_type;

  function __construct()
    {
     session_start();
     $this->check_login();
    }
  
  private function check_login()
    {
     if(isset($_SESSION['user_ID']))
	    {
		   $this->user_ID = $_SESSION['user_ID'];
       $this->user_type = $_SESSION['user_type'];
		   $this->logged_in = true;
	    }
	 else
	    {
	     unset($this->user_ID);
        unset($this->user_type);
  		 $this->logged_in = false;
	    }
    }
  
  public function is_logged_in()
    {
      return $this->logged_in;
    }
  
  public function login($user)
    {
     if($user)
	    {
		    $this->user_ID = $_SESSION['user_ID'] = $user->get_id();
		    $this->user_type = $_SESSION['user_type'] = $user->get_user_type();
		    $this->logged_in = true;
	    }
    }
   
   public function logout()
    {
     unset($_SESSION['user_ID']);
     unset($_SESSION['user_type']);
	   unset($this->user_ID);
     unset($this->user_type);
	   $this->logged_in = false;
    }   
}
$session = new Session();
?>